#!usr/bin/node

const http = require('http'),
      {join} = require('path'),
      fs = require("fs");

http.createServer((req,res) => {
  let fileName = req.url.substr(1,req.url.length-1);
  fileName = join(__dirname,fileName);

  //ReadableStream.pipe(WritableStream)
  const rs = fs.createReadStream(fileName);

  rs.on('error',(err)=>{
    res.end(err.message);
    return ;
  });

  rs.pipe(res);
  
}).listen(8080);


